//
//  HomeCollCell.m
//  ChickenA
//
//  Created by 韦显光 on 2018/6/16.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "HomeCollCell.h"


@interface HomeCollCell ()
{
    NSTimer *time;
}
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UILabel *lb1;
@property (weak, nonatomic) IBOutlet UILabel *lb2;
@property (weak, nonatomic) IBOutlet UILabel *lb3;

@end

@implementation HomeCollCell
-(void)Cellinit:(NSDictionary*)dic
{
    _lb1.text=dic[@"goods_name"];
    _lb1.adjustsFontSizeToFitWidth=YES;
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@"%@", dic[@"now_price"]]];
    _lb2.attributedText=str;

    [_img sd_setImageWithURL:[dic[@"image"] formatUrl] placeholderImage:WXGImage(@"DefaultDownLoad") ];
    _endTime=10-[dic[@"left_second"] intValue];
//    [self setEndTime:_endTime];
    [self refreshTime:nil];
}

-(void)setEndTime:(int)endTime{
    
    if (!time) {
        time = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshTime:) userInfo:nil repeats:YES];
        [self refreshTime:time];
        [[NSRunLoop currentRunLoop] addTimer:time forMode:NSRunLoopCommonModes];
    }
 
}
- (void)refreshTime:(NSTimer *)tm
{
    
    if(_endTime<=0)
    {
        [tm invalidate];
        _lb3.text=@"00:00:00";
        
    }else
    {
        _lb3.text=[NSString stringWithFormat:@"00:00:%02d",_endTime];
        _endTime--;
    }
    _lb3.textColor=_endTime>=4?[UIColor blackColor]:[UIColor redColor];
}
@end
